//
//  MCCheckLogin.m
//  MCKit框架
//
//  Created by 李李善 on 2018/1/9.
//  Copyright © 2018年 森之源. All rights reserved.
//

#import "MCCheckLogin.h"

@implementation MCCheckLogin
//判断是否正确的手机号码
+ (BOOL)isValidMobile:(NSString *)mobile error:(NSError **)error;
{
    NSDictionary *errorUserInfo;
    
    if (mobile.length <= 0) {
        errorUserInfo = [NSDictionary dictionaryWithObject:@"请输入手机号"                                                                      forKey:NSLocalizedDescriptionKey];
        *error = [NSError errorWithDomain:kCustomErrorDomain code:eCustomErrorCodeFailure userInfo:errorUserInfo];
        return NO;
    }
    
    if (![mobile checkPhoneLength]) {
        errorUserInfo = [NSDictionary dictionaryWithObject:@"请输出合法的手机号"                                                                      forKey:NSLocalizedDescriptionKey];
        *error = [NSError errorWithDomain:kCustomErrorDomain code:eCustomErrorCodeFailure userInfo:errorUserInfo];
        return NO;
    } else {
        
        if ([mobile isPhoneNo]) {
            return YES;
        } else {
            errorUserInfo = [NSDictionary dictionaryWithObject:@"请输入正确的电话号码"                                                                      forKey:NSLocalizedDescriptionKey];
            *error = [NSError errorWithDomain:kCustomErrorDomain code:eCustomErrorCodeFailure userInfo:errorUserInfo];
            return NO;
        }
    }
}

//判断是否正确的密码格式
+ (BOOL)isValidPassword:(NSString *)password error:(NSError **)error
{
    NSDictionary *errorUserInfo;
    
    if (password.length < 6) {
        errorUserInfo = [NSDictionary dictionaryWithObject:@"密码长度必须六位以上" forKey:NSLocalizedDescriptionKey];
        *error = [NSError errorWithDomain:kCustomErrorDomain code:eCustomErrorCodeFailure userInfo:errorUserInfo];
        return NO;
    }
    else if (![password isPwd])
    {
        errorUserInfo = [NSDictionary dictionaryWithObject:@"密码不足六位或者密码过长" forKey:NSLocalizedDescriptionKey];
        *error = [NSError errorWithDomain:kCustomErrorDomain code:eCustomErrorCodeFailure userInfo:errorUserInfo];
        return NO;
        
    }
    
    return YES;
}

@end
